<script setup lang="ts">
import {DRAW_STATUS} from "~/const/common";

definePageMeta({
  layout:'admin',
  title:'提现列表',
});
const form=reactive({
  limit:20,
  page:1,
});
const {data:list,refresh}=await useServerGet('/backend/finance/getWithdrawalList',form)
const pay=async (row:any )=>{
  ElMessageBox.confirm('确定已完成打款吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then( async () => {
    const {data,code}=await usePost('/backend/finance/payment',{id:row.id})
    if(code==200){
      refresh&&refresh();
    }
  }).catch(() => {
  });
}
const current=ref();
const show=ref(false);
const row=ref()
const aduit=(item)=>{
  current.value={status:2,remark:''}
  row.value=item;
  show.value=true;
}
const aduitDo=async ()=>{
  if(!current.value.status){
    ElMessage.error('请选择审核状态');
    return;
  }
  if (!current.value.remark&&current.value.status==2) {
    ElMessage.error('请输入备注');
    return;
  }
  const {data,code}=await usePost('/backend/finance/examineWithdrawal',{id:row.value.id,...current.value})
  if(code==200){
    show.value=false;
    refresh&&refresh();
  }
}
</script>

<template>
  <div>
    <el-card class="mt-4" v-if="list">
      <el-table
          ref="multipleTable1"
          :data="list.data?.list"
          tooltip-effect="dark"
          style="width: 100%"
          align="center"
      >
        <el-table-column prop="id" label="ID"></el-table-column>
        <el-table-column prop="user_id" label="用户ID"></el-table-column>
        <el-table-column prop="money" label="提现金额"></el-table-column>
        <el-table-column prop="status" label="状态">
          <template #default="{row}">
            {{DRAW_STATUS[row.status]}}
          </template>
        </el-table-column>
        <el-table-column prop="updated_at" label="更新时间"></el-table-column>
        <el-table-column prop="created_at" label="创建时间"></el-table-column>
        <el-table-column prop="remark" label="备注"></el-table-column>
        <el-table-column label="操作">
          <template #default="{row}">
            <el-button type="primary" @click="aduit(row)" v-if="!row.status">审核</el-button>
            <el-button type="primary" @click="pay(row)" v-if="row.status==1">打款</el-button>
          </template>
        </el-table-column>
      </el-table>
      <MyPage v-model:page="form.page" v-model:perpage="form.limit" v-model:total="list.data.count" @change="refresh"></MyPage>
      </el-card>
    <el-dialog
      title="审核"
      v-model="show"
      width="500"
      align-center
      align="center"
      :before-close="()=>{show=false}">
      <el-form :model="current" label-width="80px" class="w-[400px] mx-auto">
        <el-form-item label="审核状态">
          <el-radio-group v-model="current.status">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="current.remark" type="textarea" placeholder="请输入备注"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="aduitDo">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    </div>

</template>

<style scoped lang="scss">

</style>